package com.baomidou.ant.controller;

import com.baomidou.ant.common.Result;
import com.baomidou.ant.entity.ErrorBook;
import com.baomidou.ant.service.IErrorBookService;
import com.baomidou.ant.utils.MyStringUtils;
import com.baomidou.ant.vo.Response.ResponseMyErrorVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2021-03-24
 */
@RestController
@RequestMapping("/errorBook")
public class ErrorBookController {
    @Autowired
    private IErrorBookService errorBookService;

    //错题纪录统计
    @GetMapping("/listMyError/{userId}")
    public Result listMyError(@PathVariable Integer userId){
        ErrorBook errorBook = errorBookService.queryByUserId(userId);
        if(errorBook==null){
            return Result.getFailure();
        }
        //统计数量
        int pvpNum= MyStringUtils.toInt(errorBook.getEasyPvp()).length+
                MyStringUtils.toInt(errorBook.getHardPvp()).length+
                MyStringUtils.toInt(errorBook.getNormalPvp()).length;
        int pveNum=MyStringUtils.toInt(errorBook.getEasyPve()).length+
                MyStringUtils.toInt(errorBook.getHardPve()).length+
                MyStringUtils.toInt(errorBook.getNormalPve()).length;
        int endlessNum=MyStringUtils.toInt(errorBook.getHardEndless()).length+
                MyStringUtils.toInt(errorBook.getEasyEndless()).length+
                MyStringUtils.toInt(errorBook.getNormalEndless()).length;

        ResponseMyErrorVo responseMyErrorVo = new ResponseMyErrorVo();
        //减3是因为减去0
        responseMyErrorVo.setPvpNum(pvpNum-3);
        responseMyErrorVo.setEndlessNum(endlessNum-3);
        responseMyErrorVo.setPveNum(pveNum-3);
        return Result.getSuccess().setData(responseMyErrorVo);
    }

}
